import java.util.Arrays;
import java.util.*;

public class Test {

    //448. 找到所有数组中消失的数字
    public List<Integer> findDisappearedNumbers(int[] nums) {
        int[] count = new int[nums.length + 1];
        for(int i = 0; i < nums.length; i++) {
            count[nums[i]]++;
        }

        List<Integer> list = new ArrayList<>();
        for(int i = 1; i < count.length; i++) {
            if(count[i] == 0) {
                list.add(i);
            }
        }
        return list;
    }



    //645. 错误的集合
    public int[] findErrorNums(int[] nums) {
        int[] flag = new int[nums.length];
        for(int i = 0; i < nums.length; i++) {
            flag[nums[i] - 1]++;
        }
        int k = 0;
        int[] ret = new int[2];
        for(int i = 0; i < flag.length; i++) {
            if(flag[i] == 2) {
                ret[0] = i + 1;
            } else if (flag[i] == 0) {
                ret[1] = i + 1;
            }
        }
        return ret;
    }



    //NC61 两数之和
    public int[] twoSum (int[] numbers, int target) {
        int[] ret = new int[2];
        // Key记录 target 减去 一个加数的值， Value 记录这个加数的下标
        Map<Integer, Integer> map = new HashMap<>();
        map.put(target - numbers[0], 0);
        for (int i = 1; i < numbers.length; i++) {
            if (map.get(numbers[i]) != null) {
                ret[0] = map.get(numbers[i]) + 1;
                ret[1] = i + 1;
            } else {
                map.put(target - numbers[i], i);
            }
        }

        return ret;
    }
}
